<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\service\PostService;
use think\facade\Db;

class PageController extends HomeBaseController
{
    
    // protected $view_share_var = array(
    //     PRODCUT_CATEGORY_LIST => array( // 产品分类列表 ，对应控制器ProductController,  
    //         'position' => false,'type'=>3,'isSelect'=>true,'controller'=>'product'
    //     ), 
    //     NEWS_CATEGORY_LIST => array(//新闻分类列表,对应控制器NewsController
    //         'position' => false,'type'=>3,'isSelect'=>true,'controller'=>'news'
    //     ), 
    //     CASE_CATEGORY_LIST => array(//案例分类列表，对应控制器CaseController
    //         'position' => false,'type'=>3,'isSelect'=>true,'controller'=>'case'
    //     ),  
    //     PRODCUT_RECOMMEND_LIST => array( // 产品推荐列表 ，对应控制器ProductController,  
    //         'position' => false,'type'=>2,'isSelect'=>false,'controller'=>'product'
    //     ),
    //     NEWS_RECOMMEND_LIST => array( // 新闻推荐列表 ，对应控制器NewsController,  
    //         'position' => false,'type'=>2,'isSelect'=>false,'controller'=>'news'
    //     ),
    //     CASE_RECOMMEND_LIST => array( // 案例推荐列表 ，对应控制器CaseController,  
    //         'position' => false,'type'=>2,'isSelect'=>false,'controller'=>'case'
    //     ),        
    // ); 
    
    /**
     * 页面管理
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        
        $postService = new PostService();
        $pageId      = $this->request->param('id', 0, 'intval');
        $page        = $postService->publishedPage($pageId);
        
        if (empty($page)) {
            abort(404, ' 页面不存在!');
        }
        $clientele = Db::name('clientele')->field('post_title,more')->limit(2)->select()->toArray();
        foreach ($clientele as &$value){
            $value['more'] = json_decode($value['more'],TRUE);
        }
        $this->assign('clientele',$clientele);

        $this->assign('page', $page);
        
        $more = $page['more'];

        $tplName = empty($more['template']) ? 'page' : $more['template'];     
        
             
        return $this->fetch("/$tplName");
    }

}
